package com.x52im.rainbowchat.http.logic.pay.alipay;

import com.alipay.api.AlipayApiException;
import com.x52im.rainbowchat.http.logic.dto.AlipayCertverifyDTO;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class MCertverifyRedirect extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doAll(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doAll(req, resp);
    }

    protected void doAll(HttpServletRequest req, HttpServletResponse resp) {
        String authCode = req.getParameter("auth_code");
        String certVerifyId = req.getParameter("cert_verify_id");
        AlipayCertverifyDTO dto = new AlipayCertverifyDTO();
        dto.setAuthCode(authCode);
        dto.setVerifyId(certVerifyId);
        try {
            new MCertverify().getAccessTokenByAuthCode(dto, false);
        } catch (AlipayApiException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
